<template>
    <div class="app-container">
  
      <el-row :gutter="10" class="mb8">
 
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['animalExam:animalExam:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="animalExamList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="动物申请编号" align="center" prop="animalApplicationId" />
        <el-table-column label="数量" align="center" prop="animalApplicationNumber" />
        <el-table-column label="申请日期" align="center" prop="animalApplicationDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.animalApplicationAge, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="申请状态" align="center" prop="typeMsg" />
        <el-table-column label="申请动物" align="center" prop="animalApplicationBy2" />
        <el-table-column label="申请描述" align="center" prop="animalApplicationBy3" />
        <el-table-column label="教师名" align="center" prop="teacherName" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              :disabled="scope.row.typeMsg=='已提交'?false:true"
              @click="handleUpdate(scope.row)"
            
            >通过</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              :disabled="scope.row.typeMsg=='已提交'?false:true"
              @click="handleDelete(scope.row)"
        
            >退回</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              :disabled="scope.row.typeMsg=='动物申请已审批'?false:true"
              @click="handleEdit(scope.row)"
         
            >归档</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
    
    </div>
  </template>
  
  <script>
  import {examAnimalback ,listAnimalExam, examAnimalPass, examAnimalGoDOwn, addAnimalExam, updateAnimalExam } from "@/api/animalExam/animalExam";
  
  export default {
    name: "AnimalExam",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 动物审批表格数据
        animalExamList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          animalId: null,
          animalApplicationNumber: null,
          animalApplicationSex: null,
          animalApplicationDate: null,
          animalApplicationBy1: null,
          animalApplicationBy2: null,
          animalApplicationBy3: null,
          teacherId: null,
          studentId: null
        },
        // 表单参数
        form: {},
        //站内信的空form
        from1:{},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询动物审批列表 */
      getList() {
        this.loading = true;
        listAnimalExam(this.queryParams).then(response => {
          this.animalExamList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          animalApplicationId: null,
          animalId: null,
          animalApplicationNumber: null,
          animalApplicationSex: null,
          animalApplicationAge: null,
          animalApplicationBy1: null,
          animalApplicationBy2: null,
          animalApplicationBy3: null,
          teacherId: null,
          studentId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.animalApplicationId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加动物审批";
      },
           /** 归档 */
           handleEdit(row) {
        this.reset();
        const animalApplicationId = row.animalApplicationId || this.ids
        examAnimalGoDOwn(animalApplicationId).then(response => {
          if(response.code==200){
          this.$message.success("归档成功")
          this.getList();
         }
       
        });
      },
      /** 审批通过按钮 */
      handleUpdate(row) {
        this.reset();
        const animalApplicationId = row.animalApplicationId || this.ids
        examAnimalPass(animalApplicationId).then(response => {
          this.from1
          if(response.code==200){
          this.$message.success("提交成功")
          this.getList();
         }
       
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.animalApplicationId != null) {
              updateAnimalExam(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addAnimalExam(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 动物申请退回操作 */
      handleDelete(row){
        this.reset();
        const animalApplicationId = row.animalApplicationId || this.ids
        examAnimalback(animalApplicationId).then(response => {
          if(response.code==200){
          this.$message.success("退回成功")
          this.getList();
         }
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('animalExam/animalExam/export', {
          ...this.queryParams
        }, `animalExam_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  